﻿using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Vecen.BangChuang.Migrations
{
    public partial class OrderCostPrice : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder) {
            migrationBuilder.DropTable(name: "ProductPrices");

            migrationBuilder.AddColumn<DateTime>(name: "LastPutOnTime", table: "Promotions", nullable: true);

            migrationBuilder.AddColumn<decimal>(name: "AgentPrice", table: "Products", nullable: false,
                defaultValue: 0m);

            migrationBuilder.AddColumn<decimal>(name: "CostPrice", table: "Products", nullable: false,
                defaultValue: 0m);

            migrationBuilder.AddColumn<decimal>(name: "ExFactoryPrice", table: "Products", nullable: false,
                defaultValue: 0m);

            migrationBuilder.AddColumn<DateTime>(name: "LastPutOnTime", table: "Products", nullable: true);

            migrationBuilder.AddColumn<decimal>(name: "CostPriceOfTheTime", table: "OrderItems", nullable: false,
                defaultValue: 0m);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropColumn(
                name: "LastPutOnTime",
                table: "Promotions");

            migrationBuilder.DropColumn(
                name: "AgentPrice",
                table: "Products");

            migrationBuilder.DropColumn(
                name: "CostPrice",
                table: "Products");

            migrationBuilder.DropColumn(
                name: "ExFactoryPrice",
                table: "Products");

            migrationBuilder.DropColumn(
                name: "LastPutOnTime",
                table: "Products");

            migrationBuilder.DropColumn(
                name: "CostPriceOfTheTime",
                table: "OrderItems");

            migrationBuilder.AlterColumn<decimal>(
                name: "AgentPriceOfTheTime",
                table: "OrderItems",
                nullable: true,
                oldClrType: typeof(decimal));

            migrationBuilder.CreateTable(
                name: "ProductPrices",
                columns: table => new
                {
                    Id = table.Column<int>(nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    Price = table.Column<decimal>(nullable: true),
                    PriceType = table.Column<string>(nullable: true),
                    ProductId = table.Column<int>(nullable: false),
                    Remark = table.Column<string>(maxLength: 512, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ProductPrices", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ProductPrices_Products_ProductId",
                        column: x => x.ProductId,
                        principalTable: "Products",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_ProductPrices_ProductId",
                table: "ProductPrices",
                column: "ProductId");
        }
    }
}
